package com.ruoyi.project.system.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.MiddleTableData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.system.mapper.TFillingMapper;
import com.ruoyi.project.system.domain.TFilling;
import com.ruoyi.project.system.service.ITFillingService;

/**
 * 填空题库Service业务层处理
 * 
 * @author ruoyi
 * @date 2020-05-09
 */
@Service
public class TFillingServiceImpl implements ITFillingService 
{
    @Autowired
    private TFillingMapper tFillingMapper;

    /**
     * 查询填空题库
     * 
     * @param fillingId 填空题库ID
     * @return 填空题库
     */
    @Override
    public TFilling selectTFillingById(Integer fillingId)
    {
        return tFillingMapper.selectTFillingById(fillingId);
    }

    /**
     * 查询填空题库列表
     * 
     * @param tFilling 填空题库
     * @return 填空题库
     */
    @Override
    public List<TFilling> selectTFillingList(TFilling tFilling)
    {
        return tFillingMapper.selectTFillingList(tFilling);
    }

    /**
     * 新增填空题库
     * 
     * @param tFilling 填空题库
     * @return 结果
     */
    @Override
    public int insertTFilling(TFilling tFilling)
    {
        tFilling.setCreateTime(DateUtils.getNowDate());
        return tFillingMapper.insertTFilling(tFilling);
    }

    /**
     * 修改填空题库
     * 
     * @param tFilling 填空题库
     * @return 结果
     */
    @Override
    public int updateTFilling(TFilling tFilling)
    {
        return tFillingMapper.updateTFilling(tFilling);
    }

    /**
     * 批量删除填空题库
     * 
     * @param fillingIds 需要删除的填空题库ID
     * @return 结果
     */
    @Override
    public int deleteTFillingByIds(Integer[] fillingIds)
    {
        deleteMiddle(fillingIds[1],fillingIds[0]);
        return tFillingMapper.deleteTFillingByIds(fillingIds);
    }

    /**
     * 删除填空题库信息
     * 
     * @param fillingId 填空题库ID
     * @return 结果
     */
    @Override
    public int deleteTFillingById(Integer fillingId)
    {
        return tFillingMapper.deleteTFillingById(fillingId);
    }


    @Override
    public int addMiddle(Integer  subject_id ,Integer multiSel_id) {
        MiddleTableData middleTableData = new MiddleTableData();
        return tFillingMapper.addMiddle(middleTableData.FZMap(subject_id,multiSel_id));
    }

    @Override
    public int updateMiddle(Integer  subject_id ,Integer multiSel_id,String courseName) {
        MiddleTableData middleTableData = new MiddleTableData();
        Map map = middleTableData.FZMap(subject_id, multiSel_id);
        map.put("courseName",courseName);
        return tFillingMapper.updateMiddle(map);
    }

    @Override
    public int deleteMiddle(Integer  subject_id ,Integer multiSel_id) {

        MiddleTableData middleTableData = new MiddleTableData();
        return tFillingMapper.deleteMiddle(middleTableData.FZMap(subject_id,multiSel_id));
    }
}
